package com.ddh.codeduck.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.codeduck.pojo.dto.CodeDuckQuestionCategoryDTO;
import com.codeduck.pojo.entity.CodeDuckQuestionCategory;
import com.codeduck.pojo.req.CodeDuckQuestionCategoryPageReq;
import com.ddh.codeduck.service.ICodeDuckQuestionCategoryService;
import com.codeduck.pojo.vo.CodeDuckQuestionCategoryVO;
import com.ddhcodeduck.common.result.BaseResponse;
import com.ddhcodeduck.common.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 题目分类表 前端控制器
 * </p>
 *
 * @author ddh
 * @since 2025-07-03
 */
@RestController
@RequestMapping("/admin/codeDuckQuestionCategory")
@Api(tags = "题目分类表")
public class CodeDuckQuestionCategoryController {

    @Resource
    private ICodeDuckQuestionCategoryService codeDuckQuestionCategoryService;

    /**
     * 分页查询题目分类
     */
    @PostMapping("/listQuestionCategory")
    @ApiOperation("分页查询题目分类")
    public BaseResponse<IPage<CodeDuckQuestionCategoryVO>> listQuestionCategory(@RequestBody CodeDuckQuestionCategoryPageReq codeDuckQuestionCategoryPageReq) {
        return ResultUtils.success(codeDuckQuestionCategoryService.listQuestionCategory(codeDuckQuestionCategoryPageReq));
    }

    /**
     * 新增或者修改题目分类
     */
    @PostMapping("/saveOrUpdateQuestionCategory")
    @ApiOperation(value = "新增或者修改题目分类")
    public BaseResponse<Boolean> saveOrUpdateQuestionCategory(@RequestBody CodeDuckQuestionCategoryDTO codeDuckQuestionCategoryDTO) {
        boolean result = codeDuckQuestionCategoryService.mySaveOrUpdate(codeDuckQuestionCategoryDTO);
        return ResultUtils.success(result);
    }

    /**
     * 根据ID查询题目分类
     */
    @GetMapping("/getQuestionCategoryById")
    @ApiOperation(value = "根据ID查询题目分类")
    public BaseResponse<CodeDuckQuestionCategory> getQuestionCategoryById(@RequestParam("id") String id) {
        CodeDuckQuestionCategory byId = codeDuckQuestionCategoryService.getById(id);
        return ResultUtils.success(byId);
    }

    /**
     * 批量删除或者单个删除
     */
    @PostMapping("/deleteQuestionCategoryByIds")
    @ApiOperation(value = "批量删除或者单个删除")
    public BaseResponse<Boolean> deleteQuestionCategoryByIds(@RequestBody List<String> ids) {
        return ResultUtils.success(codeDuckQuestionCategoryService.removeByIds(ids));
    }
}
